package com.simplenix.nicasio.tags;

import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.JspFragment;
import javax.servlet.jsp.tagext.SimpleTagSupport;

/**
 *
 * @author fronald
 */
public class DocReady extends SimpleTagSupport {

	private String function;

	/**
	 * Called by the container to invoke this tag.
	 * The implementation of this method is provided by the tag library developer,
	 * and handles all tag processing, body iteration, etc.
	 */
	@Override
	public void doTag() throws JspException {
		JspWriter out = getJspContext().getOut();

		try {
			JspFragment f = getJspBody();
			if (f != null) {
				f.invoke(out);
			}
			out.println("$(document).ready(" + this.getFunction() + ");");

		} catch (java.io.IOException ex) {
			throw new JspException("Error in DocReady tag", ex);
		}
	}

	/**
	 * @return the function
	 */
	public String getFunction() {
		return function;
	}

	/**
	 * @param function the function to set
	 */
	public void setFunction(String function) {
		this.function = function;
	}

}
